﻿<phone:PhoneApplicationPage
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:bh="clr-namespace:Odyssey.Behaviors;assembly=Odyssey"
    xmlns:ctrls="clr-namespace:Odyssey.Controls;assembly=Odyssey"
    xmlns:fx="clr-namespace:Odyssey.Effects;assembly=Odyssey"
    xmlns:vm="clr-namespace:OdcTest.ViewModels"
    xmlns:ia="clr-namespace:Odyssey.Interactivity;assembly=Odyssey"
    xmlns:ic="clr-namespace:Microsoft.Expression.Interactivity.Core;assembly=Microsoft.Expression.Interactions" 
    xmlns:primitives="clr-namespace:Odyssey.Controls.Primitives;assembly=Odyssey"
    xmlns:Custom="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" 
    xmlns:il="clr-namespace:Microsoft.Expression.Interactivity.Layout;assembly=Microsoft.Expression.Interactions" 
    x:Class="OdcTest.Views.OdcListBoxPage"
    SupportedOrientations="Portrait" Orientation="Portrait" 
    mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="480" bh:TiltEffect.IsTiltEnabled="True"
    shell:SystemTray.IsVisible="True">

    <phone:PhoneApplicationPage.Resources>
        <DataTemplate x:Key="menuItemTemplate">
            <ctrls:ContextMenu>
                <ctrls:ContextMenuItem Content="Insert Item" Command="{Binding InsertCommand}" InvokeOnMenuClosed="True"/>
                <ctrls:ContextMenuItem Content="Tap to show message" Command="{Binding MenuCommand}" />
                <ctrls:ContextMenuItem Content="Delete" Command="{Binding DeleteCommand}"  />
                <ctrls:ContextMenuItem Content="Disabled Item" IsEnabled="False"/>
                <ctrls:ContextMenuItem Content="Rename" Command="{Binding RenameCommand}" InvokeOnMenuClosed="True"/>
            </ctrls:ContextMenu>
        </DataTemplate>

        <DataTemplate x:Key="menuItemTemplate2">
            <ctrls:ContextMenu>
                <ctrls:ContextMenuItem Content="main menu"/>
                <ctrls:ContextMenuItem Content="Menu 2 this item is not data bound" Command="{Binding MenuCommand}" />
            </ctrls:ContextMenu>
        </DataTemplate>
    </phone:PhoneApplicationPage.Resources>

    <phone:PhoneApplicationPage.FontFamily>
        <StaticResource ResourceKey="PhoneFontFamilyNormal"/>
    </phone:PhoneApplicationPage.FontFamily>
    <phone:PhoneApplicationPage.FontSize>
        <StaticResource ResourceKey="PhoneFontSizeNormal"/>
    </phone:PhoneApplicationPage.FontSize>
    <phone:PhoneApplicationPage.Foreground>
        <StaticResource ResourceKey="PhoneForegroundBrush"/>
    </phone:PhoneApplicationPage.Foreground>

    <phone:PhoneApplicationPage.DataContext>
        <vm:DataViewModel/>
    </phone:PhoneApplicationPage.DataContext>

    <Custom:Interaction.Triggers>
        <Custom:EventTrigger EventName="ItemInvoked" SourceName="listBox">
            <bh:ContimuumEffectAction Mode="Master" Duration="0:0:0.25" />
            <ic:NavigateToPageAction TargetPage="/Views/DetailPage.xaml"/>
        </Custom:EventTrigger>
    </Custom:Interaction.Triggers>

    <phone:PhoneApplicationPage.ApplicationBar>
        <shell:ApplicationBar IsVisible="True" IsMenuEnabled="False">
            <shell:ApplicationBarIconButton IconUri="/Images/appbar.check.rest.png" Text="OK"/>
            <shell:ApplicationBarIconButton IconUri="/Images/appbar.cancel.rest.png" Text="Cancel"/>
        </shell:ApplicationBar>
    </phone:PhoneApplicationPage.ApplicationBar>

    <Grid x:Name="LayoutRoot" Background="Transparent">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
            <TextBlock x:Name="ApplicationTitle" Text="ODYSSEY" Style="{StaticResource PhoneTextNormalStyle}"/>
            <TextBlock x:Name="PageTitle" Text="OdcListBox" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}" 
                       ctrls:ContextMenu.ContextMenuTemplate="{StaticResource menuItemTemplate2}"  />
        </StackPanel>

        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <ctrls:OdcListBox x:Name="listBox" ItemsSource="{Binding Items}" ItemHeight="80"
                              SelectedItem="{Binding SelectedItem, Mode=TwoWay}">
                <ctrls:OdcListBox.ItemContainerStyle>
                    <Style TargetType="ctrls:OdcListBoxItem">
                        <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="ctrls:OdcListBoxItem">
                                    <Border ctrls:ContextMenu.ContextMenuTemplate="{StaticResource menuItemTemplate}"  ctrls:ContextMenu.IsOpen="{Binding IsContextMenuOpen, Mode=TwoWay}">
                                        <Border.Triggers>
                                            <EventTrigger>
                                                <BeginStoryboard>
                                                    <Storyboard>
                                                        <DoubleAnimation Duration="0" Storyboard.TargetName="grid" Storyboard.TargetProperty="Opacity" To="1"/>
                                                        <DoubleAnimation Duration="0" Storyboard.TargetName="plane" Storyboard.TargetProperty="GlobalOffsetX" To="0"/>
                                                    </Storyboard>
                                                </BeginStoryboard>
                                            </EventTrigger>
                                        </Border.Triggers>
                                        <Grid x:Name="grid" Opacity="0" fx:FeatherEffect.IsElement="True" CacheMode="BitmapCache"  Height="80">
                                            <Grid.Projection>
                                                <PlaneProjection x:Name="plane" GlobalOffsetX="0" />
                                            </Grid.Projection>
                                            <ctrls:CommandButton  BorderThickness="0" Width="80" Height="80" VerticalAlignment="Center"
                                                                  HorizontalAlignment="Left" Margin="0" Padding="0"
                                                                 Command="{Binding OpenContextMenu}" >
                                                <ctrls:CommandButton.Template>
                                                    <ControlTemplate>
                                                        <Rectangle Fill="{StaticResource PhoneChromeBrush}" Width="72" Height="72" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="0,5"/>
                                                    </ControlTemplate>
                                                </ctrls:CommandButton.Template>
                                            </ctrls:CommandButton>
                                            <!--<Rectangle Fill="{StaticResource PhoneChromeBrush}" Width="72" Height="72" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="0,5"/>-->
                                            <TextBlock Text="{Binding Name}" 
                                                   fx:ContinuumEffect.IsItem="{Binding IsSelected, RelativeSource={RelativeSource TemplatedParent}}"
                                                   FontSize="{StaticResource PhoneFontSizeExtraLarge}" Margin="90,0,0,0" VerticalAlignment="Center"/>
                                        </Grid>
                                    </Border>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </ctrls:OdcListBox.ItemContainerStyle>
                <ctrls:OdcListBox.Template>
                    <ControlTemplate>
                        <ScrollViewer>
                            <primitives:VirtualizingRowPanel>
                                <!--adding a fluid move behavior to apply a visual effect when the item gets deleted:-->
                                <Custom:Interaction.Behaviors>
                                    <il:FluidMoveBehavior Duration="0:0:0.25" AppliesTo="Children" InitialTag="Element"  Tag="DataContext" IsActive="True">
                                        <il:FluidMoveBehavior.EaseY>
                                            <QuadraticEase EasingMode="EaseIn"/>
                                            <!--<ElasticEase/>-->
                                        </il:FluidMoveBehavior.EaseY>
                                    </il:FluidMoveBehavior>
                                </Custom:Interaction.Behaviors>
                            </primitives:VirtualizingRowPanel>
                        </ScrollViewer>
                    </ControlTemplate>
                </ctrls:OdcListBox.Template>
            </ctrls:OdcListBox>
        </Grid>
    </Grid>

</phone:PhoneApplicationPage>
